package com.ygou.service.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ygou.mapper.AnnouncementMapper;
import com.ygou.mapper.GoodsAppraisesMapper;
import com.ygou.mapper.GoodsMapper;
import com.ygou.mapper.OrdersMapper;
import com.ygou.mapper.UsersMapper;
import com.ygou.pojo.AnnouncementExample;
import com.ygou.pojo.GoodsExample;
import com.ygou.pojo.OrdersExample;
import com.ygou.pojo.OrdersExample.Criteria;
import com.ygou.service.AnnouncementService;
import com.ygou.service.CountService;
import com.ygou.service.UsersService;
import com.ygou.utils.Tools;

@Service
public class CountServiceImpl implements CountService {
	@Autowired
	GoodsMapper goodsMapper;
	@Autowired
	OrdersMapper ordersMapper;
	@Autowired
	GoodsAppraisesMapper goodsAppraisesMapper;
	@Autowired
	UsersMapper usersMapper;
	@Autowired
	AnnouncementMapper announcementMapper;
	@Override
	public Map<String, Object> count() {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("order", ordersMapper.countByExample(null));
		map.put("suser", usersMapper.countByExample(null));
		map.put("goods", goodsMapper.countByExample(null));
		map.put("goodsAppraises", goodsAppraisesMapper.countByExample(null));
		return map;
	}

	@Override
	public Map<String, Object> countByExample() {
		// 订单的
		OrdersExample example = new OrdersExample();
		Criteria c = example.createCriteria();
		Map<String, Object> map = new HashMap<String, Object>();
		// 未发货
		c.andIssendEqualTo((byte) 0);
		map.put("wsend", ordersMapper.countByExample(example));
		// 未收货
		c.andIstakeoverEqualTo((byte) 0);
		map.put("wtakeover", ordersMapper.countByExample(example));
		// 未付款
		c.andIspayEqualTo((byte) 0);
		map.put("wpay", ordersMapper.countByExample(example));
		// 已付款
		c.andIspayEqualTo((byte) 1);
		map.put("ypay", ordersMapper.countByExample(example));
		// 未退款
		c.andIsrefundEqualTo((byte) 0);
		map.put("wrefund", ordersMapper.countByExample(example));
		// 已退款
		c.andIsrefundEqualTo((byte) 1);
		map.put("yrefund", ordersMapper.countByExample(example));
		
		// 商品的
		GoodsExample gexample = new GoodsExample();
		com.ygou.pojo.GoodsExample.Criteria gc = gexample.createCriteria();
		// 上架
		gc.andIssaleEqualTo((byte) 1);
		map.put("ssale", goodsMapper.countByExample(gexample));
		// 下架
		gc.andIssaleEqualTo((byte) 0);
		map.put("xsale", goodsMapper.countByExample(gexample));
		// 今天上架
		gc.andIssaleEqualTo((byte) 1);
		gc.andCreatetimeLike("%"+Tools.getCurrentMonth(new Date())+"%");
		map.put("nssale", goodsMapper.countByExample(gexample));
		//公告的
		AnnouncementExample aexample = new AnnouncementExample();
		//公告消息
		aexample.setOrderByClause("createtime desc");
		map.put("announce",announcementMapper.selectByExample(aexample));
		return map;
	}

	@Override
	public int sum() {
		return ordersMapper.sum();
	}

}
